<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="Keep Team">
    
    <title>
        
            蓝桥刷的一些典型题目 |
        
        Keep Theme
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    <link rel="shortcut icon" href="/images/logo.svg">
    
<link rel="stylesheet" href="/css/font-awesome.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"example.com","root":"/","language":"en"};
    KEEP.theme_config = {"toc":{"enable":false,"number":false,"expand_all":false,"init_open":false},"style":{"primary_color":"#0066CC","avatar":"/images/head.png","favicon":"/images/logo.svg","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":false,"scale":false},"first_screen":{"enable":true,"background_img":"/images/pic.jpg","description":"你应该活在自己的热爱里，而不是别人的眼光里。"},"scroll":{"progress_bar":{"enable":false},"percent":{"enable":false}}},"local_search":{"enable":false,"preload":false},"code_copy":{"enable":false,"style":"default"},"pjax":{"enable":false},"lazyload":{"enable":false},"version":"3.4.5"};
    KEEP.language_ago = {"second":"%s seconds ago","minute":"%s minutes ago","hour":"%s hours ago","day":"%s days ago","week":"%s weeks ago","month":"%s months ago","year":"%s years ago"};
  </script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
<div class="progress-bar-container">
    

    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                Keep Theme
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/"
                            >
                                HOME
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/archives"
                            >
                                ARCHIVES
                            </a>
                        </li>
                    
                    
                </ul>
            </div>
            <div class="mobile">
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/">HOME</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/archives">ARCHIVES</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">蓝桥刷的一些典型题目</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="/images/head.png">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">Keep Team</span>
                        
                            <span class="author-label">Lv1</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;
        <span class="pc">2022-04-11 09:13:24</span>
        <span class="mobile">2022-04-11 09:13</span>
    </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fas fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/123/">123</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/tags/456/">456</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <p>​    比上课有意思。。上算法课都听的些什么，果然还是得靠自学，比赛促学。</p>
<ul>
<li>欧几里得</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">int</span> <span class="title">judge</span><span class="params">(<span class="type">int</span> a,<span class="type">int</span> b)</span></span>&#123;</span><br><span class="line">  <span class="keyword">if</span>(b==<span class="number">0</span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> a;<span class="comment">//a就是最小公约数</span></span><br><span class="line">  &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">judge</span>(b,a%b);<span class="comment">//继续辗转相除</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<ul>
<li>分解因子 暴力</li>
</ul>
<p><img src="C:\Users\86136\AppData\Roaming\Typora\typora-user-images\image-20220306224128482.png" alt="image-20220306224128482"></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;vector&gt;</span><br><span class="line">#include &lt;cmath&gt;</span><br><span class="line">using namespace std;</span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">  long long num = 0;</span><br><span class="line">  vector&lt;long long&gt; vec;</span><br><span class="line">  long long n = 2021041820210418;</span><br><span class="line">  for(long long i = 1;i&lt;sqrt(n);i++)&#123;</span><br><span class="line">    if(n%i==0) &#123;vec.push_back(i);vec.push_back(n/i);&#125;//这里刚开始忘记把n/i也加上了</span><br><span class="line">  &#125;</span><br><span class="line">  if(sqrt(n)*sqrt(n)==n)&#123;vec.push_back(sqrt(n));&#125;</span><br><span class="line">  for(int i = 0;i&lt;vec.size();i++)&#123;</span><br><span class="line">    for(int j = 0;j&lt;vec.size();j++)&#123;</span><br><span class="line">      for(int k = 0;k&lt;vec.size();k++)&#123;</span><br><span class="line">        if(vec[i]*vec[j]*vec[k]==n) num++;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  cout&lt;&lt;num;</span><br><span class="line">  // 请在此输入您的代码</span><br><span class="line">  //总的思路也就是需要先把暴力的空间减少，然后再遍历</span><br><span class="line">  return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>发现环——无向图 拓扑排序 求环</p>
<p><img src="C:\Users\86136\AppData\Roaming\Typora\typora-user-images\image-20220315151639201.png" alt="image-20220315151639201"></p>
</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;queue&gt;</span><br><span class="line">#include &lt;vector&gt;</span><br><span class="line">using namespace std;</span><br><span class="line">const int N = 1e5 + 10;</span><br><span class="line">int n;//顶点数</span><br><span class="line">int de[N] = &#123;0&#125;;//顶点度数</span><br><span class="line">vector&lt;int&gt; nd[N];//边对应关系 二维</span><br><span class="line">queue&lt;int&gt; q;//队列</span><br><span class="line">bool huan[N];</span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">  // 请在此输入您的代码</span><br><span class="line">  cin&gt;&gt;n;</span><br><span class="line">  //创建邻接矩阵</span><br><span class="line">  int u,v;</span><br><span class="line">  for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">    cin&gt;&gt;u&gt;&gt;v;</span><br><span class="line">    nd[u].push_back(v);</span><br><span class="line">    nd[v].push_back(u);//无向图</span><br><span class="line">    de[u]++;de[v]++;//两个节点的度数都加一</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">    if(de[i]&lt;=1)&#123;</span><br><span class="line">      q.push(i);//所有度数为1的点入队列</span><br><span class="line">      huan[i] = true;//该点不构成环，因为无向图中环必须度数至少为2</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  while(!q.empty())&#123;</span><br><span class="line">    int front = q.front();//弹出第一个度数为1的点</span><br><span class="line">    q.pop();</span><br><span class="line">    for(int i = 0;i&lt;nd[front].size();i++)&#123;</span><br><span class="line">      de[nd[front][i]]--;//与该点相邻的顶点度数减一</span><br><span class="line"></span><br><span class="line">      if(huan[nd[front][i]]) continue;</span><br><span class="line">      if(de[nd[front][i]]&lt;=1)&#123;</span><br><span class="line">        q.push(nd[front][i]);//度数为1的点入队列</span><br><span class="line">        huan[nd[front][i]] = true;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">    if(!huan[i]) cout&lt;&lt;i&lt;&lt;&quot; &quot;; </span><br><span class="line">  &#125;</span><br><span class="line">  return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>全排列_最大乘积</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></figure>

<ul>
<li>数学公式 约数</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">数学公式：</span><br><span class="line"></span><br><span class="line">任意一个正整数 X 都可以表示成若干个质数乘积的形式，</span><br><span class="line"></span><br><span class="line">即 X = p1^a1*p2^a2*p3^a3......pk^ak</span><br><span class="line"></span><br><span class="line">约数个数 ans= (a1 + 1)(a2 + 1)……(ak + 1)</span><br><span class="line"></span><br><span class="line">对于每一种pi都有0~ai种选法，一共ai+1种，一共有k个所以乘k次(因为每个pi的指数ai不同就能拼成不同的约数）</span><br><span class="line"></span><br><span class="line">例如：12=2*2*3=2^2*3</span><br><span class="line"></span><br><span class="line">约数个数就是(2+1)(1+1)=3*2=6</span><br><span class="line"></span><br><span class="line">所有约数分别为  1        2        3        4&lt;--2*2        6&lt;--2*3        12&lt;--2*2*3</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">//马的遍历 数组 + queue + bfs</span><br><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;queue&gt;</span><br><span class="line">#include &lt;cstring&gt;</span><br><span class="line"> #include &lt;stdio.h&gt;</span><br><span class="line">#define MAX 500</span><br><span class="line">using namespace std;</span><br><span class="line">//经典bfs 直接套模板</span><br><span class="line"></span><br><span class="line">struct node&#123;</span><br><span class="line">	int x,y,step;</span><br><span class="line">&#125;;</span><br><span class="line">bool vis[MAX][MAX] ;//一个储存是否访问的 二维数组 </span><br><span class="line">int mp[MAX][MAX] = &#123;-1&#125;;//一个储存结果 的二维数组 </span><br><span class="line">queue&lt;node&gt; q;//用于bfs的队列</span><br><span class="line"> </span><br><span class="line">int dir[8][2] = &#123;-2, -1, 2, 1, 2, -1, -2, 1, 1, 2, -1, -2, 1, -2, -1, 2&#125;;</span><br><span class="line">int sx,sy,m,n; </span><br><span class="line"> </span><br><span class="line">void bfs()&#123;</span><br><span class="line">	while(!q.empty())&#123;</span><br><span class="line">		node nd = q.front();//取出队列最前面的节点</span><br><span class="line">		q.pop();//弹出这个节点</span><br><span class="line">		mp[nd.x][nd.y] = nd.step;//储存 到该点的步数 </span><br><span class="line">		for(int i = 0;i&lt;8;i++)&#123;//8个方向广度遍历 </span><br><span class="line">			int x = nd.x+dir[i][0];</span><br><span class="line">			int y = nd.y+dir[i][1];</span><br><span class="line">			if(x&gt;n||y&gt;m||x&lt;1||y&lt;1||vis[x][y]==true)&#123;</span><br><span class="line">				continue;</span><br><span class="line">			&#125;</span><br><span class="line">			//push新点 </span><br><span class="line">			node nd1;</span><br><span class="line">			nd1.x = x;</span><br><span class="line">			nd1.y = y;</span><br><span class="line">			nd1.step = nd.step+1;</span><br><span class="line">			vis[x][y] = true;</span><br><span class="line">			q.push(nd1);</span><br><span class="line">		&#125; </span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">int main()&#123;</span><br><span class="line">	cin&gt;&gt;n&gt;&gt;m&gt;&gt;sx&gt;&gt;sy;</span><br><span class="line">	</span><br><span class="line">	node nd; </span><br><span class="line">	nd.x = sx;</span><br><span class="line">	nd.y = sy;</span><br><span class="line">	nd.step = 0;</span><br><span class="line">	vis[sx][sy] = true;</span><br><span class="line">	memset(mp, -1, sizeof(mp));</span><br><span class="line">	q.push(nd);//push起点 </span><br><span class="line">	 </span><br><span class="line">	 bfs();//广度搜索  </span><br><span class="line">	 for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">	 	for(int j = 1;j&lt;=m;j++)&#123;</span><br><span class="line">	 		printf(&quot;%-5d&quot;,mp[i][j]);</span><br><span class="line">	 	&#125;</span><br><span class="line">	 	cout&lt;&lt;endl;</span><br><span class="line">	 &#125;</span><br><span class="line">	return 0;</span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>

<h3 id="全排列"><a href="#全排列" class="headerlink" title="全排列"></a>全排列</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">//dfs实现全排列</span><br><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line">#define MAX 10</span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">int a[MAX];</span><br><span class="line">int n;</span><br><span class="line">int vis[MAX];</span><br><span class="line"></span><br><span class="line">void dfs(int k)&#123;</span><br><span class="line">	if(k==n)&#123;</span><br><span class="line">		for(int i = 0;i&lt;n;i++)</span><br><span class="line">			printf(&quot;%5d&quot;,a[i]);</span><br><span class="line">		cout&lt;&lt;endl;</span><br><span class="line">		return ;</span><br><span class="line">	&#125;</span><br><span class="line">	for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">		if(vis[i]!=1)&#123;</span><br><span class="line">			//未被访问过</span><br><span class="line">			vis[i] = 1;</span><br><span class="line">			a[k] = i;</span><br><span class="line">			dfs(k+1);</span><br><span class="line">			vis[i] = 0; </span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">	cin&gt;&gt;n;</span><br><span class="line">	dfs(0);</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h5 id="八皇后问题-dfs"><a href="#八皇后问题-dfs" class="headerlink" title="八皇后问题 dfs"></a>八皇后问题 dfs</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;cstring&gt;</span><br><span class="line">#define max 30</span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">int ans[max];</span><br><span class="line">int viscol[max];</span><br><span class="line">int visleft[max];//左上到右下同一对角线上i-j值相等但有负数，所以加上n </span><br><span class="line">int visright[max];//右上到左下统一对角线上i+j值相等，共有2n-1种 </span><br><span class="line">int n;</span><br><span class="line">int count = 0;</span><br><span class="line">void dfs(int k)&#123;</span><br><span class="line">	if(k&gt;n)&#123;</span><br><span class="line">		count++;</span><br><span class="line">		if(count&lt;=3)&#123;</span><br><span class="line">			for(int i = 1;i&lt;=n;i++)&#123;</span><br><span class="line">			cout&lt;&lt;ans[i]&lt;&lt;&quot; &quot;;</span><br><span class="line">			&#125;</span><br><span class="line">			cout&lt;&lt;endl;</span><br><span class="line">		&#125;</span><br><span class="line">		return ;</span><br><span class="line">	&#125;</span><br><span class="line">	for(int i = 1;i&lt;=n;i++)&#123;//遍历每一列 </span><br><span class="line">		if(!viscol[i]&amp;&amp;!visleft[k+n-i]&amp;&amp;!visright[k+i])&#123;</span><br><span class="line">			</span><br><span class="line">			ans[k] = i;</span><br><span class="line">			visleft[k+n-i] = 1;</span><br><span class="line">			visright[k+i] = 1;</span><br><span class="line">			viscol[i] = 1;</span><br><span class="line">			dfs(k+1);</span><br><span class="line">			viscol[i] = 0;			</span><br><span class="line">			visleft[k+n-i] = 0;</span><br><span class="line">			visright[k+i] = 0;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">	cin&gt;&gt;n;</span><br><span class="line">	</span><br><span class="line">	dfs(1);</span><br><span class="line">	cout&lt;&lt;count;</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h5 id="哈希表"><a href="#哈希表" class="headerlink" title="哈希表"></a>哈希表</h5><p>缺失的第一个正数：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;cstring&gt;</span><br><span class="line">#define MAX 500010</span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">int hash[MAX];</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">	int numSize;</span><br><span class="line">	int num;</span><br><span class="line">	cin&gt;&gt;numSize;</span><br><span class="line">	memset(hash,0,sizeof(hash));</span><br><span class="line">	for(int i = 1;i&lt;=numSize;i++)&#123;</span><br><span class="line">		cin&gt;&gt;num;</span><br><span class="line">		if(num&gt;0)&#123;</span><br><span class="line">			hash[num] = 1;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	for(int i = 1;i&lt;=numSize+1;i++)&#123;</span><br><span class="line">		if(hash[i]==0)&#123;</span><br><span class="line">			cout&lt;&lt;i;</span><br><span class="line">			return 0;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="并查集-合根植物"><a href="#并查集-合根植物" class="headerlink" title="并查集 合根植物"></a>并查集 合根植物</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#define max 1010</span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">int m,n;</span><br><span class="line">int flag[max*max];//根节点标志数组 </span><br><span class="line">int pre[max*max];</span><br><span class="line">void init()&#123;</span><br><span class="line">	for(int i = 1;i&lt;=m*n;i++)&#123;</span><br><span class="line">		pre[i] = i;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int find(int x)&#123;</span><br><span class="line">	if(x==pre[x])&#123;</span><br><span class="line">		return x;</span><br><span class="line">	&#125;</span><br><span class="line">	return pre[x] = find(pre[x]);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void join(int x,int y)&#123;</span><br><span class="line">	int nx = find(x);</span><br><span class="line">	int ny = find(y);</span><br><span class="line">	if(nx!=ny)&#123;</span><br><span class="line">		pre[nx] = ny;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">	cin&gt;&gt;m&gt;&gt;n;</span><br><span class="line">	int k;</span><br><span class="line">	cin&gt;&gt;k;</span><br><span class="line">	int count = 0;</span><br><span class="line">	init();</span><br><span class="line">	</span><br><span class="line">	for(int i = 0;i&lt;k;i++)&#123;</span><br><span class="line">		int num1,num2;</span><br><span class="line">		cin&gt;&gt;num1&gt;&gt;num2;</span><br><span class="line">		join(num1,num2);</span><br><span class="line">	&#125;</span><br><span class="line">	for(int i = 1;i&lt;=m*n;i++)&#123;</span><br><span class="line">		int f = find(i);</span><br><span class="line">		flag[f] = 1;</span><br><span class="line">	&#125;</span><br><span class="line">	for(int i = 1;i&lt;=m*n;i++)&#123;</span><br><span class="line">		if(flag[i] == 1) count++;</span><br><span class="line">	&#125;</span><br><span class="line">	cout&lt;&lt;count;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


        </div>

        

        
            <ul class="post-tags-box">
                
                    <li class="tag-item">
                        <a href="/tags/123/">#123</a>&nbsp;
                    </li>
                
                    <li class="tag-item">
                        <a href="/tags/456/">#456</a>&nbsp;
                    </li>
                
            </ul>
        

        
            <div class="article-nav">
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/2022/03/07/%E5%8C%BA%E5%9D%97%E9%93%BE%E6%BA%AF%E6%BA%90%E5%BC%80%E5%8F%91/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">Geth安装以及私链搭建</span>
                                <span class="post-nav-item">Next posts</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2020</span>
              -
            
            2022&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">Keep Team</a>
        </div>
        
        <div class="theme-info info-item">
            Powered by <a target="_blank" href="https://hexo.io">Hexo</a>&nbsp;|&nbsp;Theme&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.4.5</a>
        </div>
        
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="fas fa-arrow-up"></i>
            </li>
        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
    </ul>
</div>

    </div>

    

    <div class="image-viewer-container">
    <img src="">
</div>


    

</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/header-shrink.js"></script>

<script src="/js/back2top.js"></script>

<script src="/js/dark-light-toggle.js"></script>








<div class="post-scripts">
    
</div>



</body>
</html>
